SHELL Statement Example The following example uses the SHELL function to execute three OS-2 commands. ON ERROR GOTO ErrHandler Ext$ = CHR$(34) + " EXE" + CHR$(34) ' The child process does. DIR | FIND " EXE" | SORT Child$ = "dir | find " + Ext$ + "| sort" ProcessID = SHELL(Child$) PRINT "Process ID is." ProcessID END ErrHandler. SELECT CASE ERR CASE 73 PRINT . PRINT "You cannot use the SHELL function in DOS." CASE ELSE END SELECT END SHELL Statement ---------------------------------------------------------------------------- Action Suspends execution of the BASIC program, runs a .COM, .EXE, .BAT, or .CMD program, or a DOS or OS-2 command, and resumes execution of the BASIC program at the statement following the SHELL statement. Syntax SHELL commandstring Remarks The argument commandstring must be a valid string expression that contains the name of a program to run, and any program arguments. Any .COM file, .EXE file, .BAT program, .CMD program, DOS command, or OS-2 command that runs under the SHELL statement is called a "child process." Child processes are executed by the SHELL statement, which loads and runs a copy of COMMAND.COM (for DOS) or CMD.EXE (for OS-2) with the -C option. The -C option allows any parameters in commandstring to be passed to the child process. It also allows redirection of standard input and output, and execution of built-in commands such as DIR and PATH. The program name in commandstring can have any extension you wish. If no extension is supplied, COMMAND.COM (for DOS) or CMD.EXE (for OS-2) looks for a .COM file, then an .EXE file, and finally, a .BAT file (for DOS) or a .CMD file (for OS-2). If COMMAND.COM or CMD.EXE is not found, BASIC generates the error message File not found. BASIC does not generate an error if COMMAND.COM or CMD.EXE cannot find the file specified in commandstring, but the operating system generates an error message. COMMAND.COM or CMD.EXE treat as program parameters any text separated from the program name by at least one blank. BASIC remains in memory while the child process is running. When the child process finishes, BASIC continues. If you omit the argument commandstring, SHELL gives you a new shell (COMMAND.COM for DOS or CMD.EXE for OS-2). You then can enter operating-system commands at the prompt. Use the EXIT command to return to BASIC. Note If you are using OS-2, make sure that the SET COMSPEC configuration command in your CONFIG.SYS file specifies the path for the CMD.EXE file. If the path for CMD.EXE is not set, BASIC generates an error message when SHELL searches for the CMD.EXE file. See Also SHELL Function Examples The following example shows how a single SHELL statement starts up a new COMMAND.COM. ' Get a new COMMAND.COM ' Type EXIT at the operating system prompt to return to this program. SHELL If the name of a any executable file or command is provided as an argument to the SHELL statement, that command will be executed as if it had been invoked from the operating-system prompt. When the program is finished, control returns to BASIC. The following use of the SHELL statement illustrates how to display a directory listing to check the creation time of a file. SHELL "DIR | MORE"